import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

// 用户请求前缀
const PREFIX = '/api/user-service';

/**
 * 用户登陆提交数据类型
 */
export interface LoginData {
  username: string;
  password: string;
}

export interface LoginRes {
  token: string;
}

/**
 * 用户注册提交数据类型
 */
export interface RegisterDataType {
  userAccount: string,
  userPassword: string,
  checkPassword: string,
}

/**
 * 登陆
 * @param data 
 * @returns 
 */
export function login(data: LoginData) {
  return axios.post(`${PREFIX}/user/login`, data);
}

export function logout() {
  return axios.post<LoginRes>(`${PREFIX}/user/logout`);
}

/**
 * 获取当前登陆用户信息
 * @returns 
 */
export function getUserInfo() {
  return axios.get<UserState>(`${PREFIX}/user/get/currentLoginUser`, {
  });
}

export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>(`${PREFIX}/user/menu`);
}

/**
 * 用户注册
 * @param data 
 * @returns 
 */
export async function register(data: RegisterDataType) {
  return axios.post(`${PREFIX}/user/register`, data)
}
